package api

import (
	"pd/modules"
	"pd/modules/allowed_requrl"

	"github.com/gin-gonic/gin"
)

var handler = &Handler{}

// allowed_requrl 的http实例，会实现gin的http Handler
type Handler struct {
	svc allowed_requrl.Service
}

// Deprecated: Use GinConfig and init 
func NewArHttpHandler(svc allowed_requrl.Service) *Handler {
	return &Handler{
		svc: svc,
	}
}

func (h *Handler) GinRegistry(r gin.IRouter) {
	r.POST("/allowed_requrl/name", h.createAllowed_requrl)
}

func (h *Handler) GinConfig() {
	// if apps.HostService == nil {
	// 	panic("dependence host service required")
	// }
	// //从IOC里面获取HostService
	// h.svc = apps.HostService

	// 但是这样获取的方式有些尴尬,采用GetImpl
	h.svc = modules.GetImpl(allowed_requrl.AppName).(allowed_requrl.Service)
}

func (h *Handler) GinName() string {
	return allowed_requrl.AppName
}

func init() {
	modules.RegistryGins(handler)
}
